﻿using IdentityServer4.AccessTokenValidation;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace Order.MicroService.Api.Config
{
    public class AuthorizeConfig
    {
        public static void RegisterAuthorizationServer(IServiceCollection services)
        {
            var identityServerUrl = BaseConfigInfo.IdentityServerUrl;

            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
               .AddIdentityServerAuthentication(options =>
               {
                   options.Authority = identityServerUrl;//id4服务地址
                   options.ApiName = "AccountServiceResource";//id4 api资源里的apiname
                   options.RequireHttpsMetadata = false; //不使用https
                   options.SupportedTokens = SupportedTokens.Both;
               });
        }
    }
}
